<template>
  <div class="header-box">
    <span class="header-time">{{ currentTime }}</span>
    <p class="header-title">沙河路街道办事处三维可视化智慧管理系统</p>
    <span></span>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';
import moment from 'moment';

let timer: any = null;
const currentTime = ref('');

/**
 * 获取当前时间
 */
const getCurrentTime = () => {
  if (timer) {
    clearInterval(timer);
  }
  currentTime.value = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');

  timer = setInterval(() => {
    currentTime.value = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
  }, 1000)
}

onMounted(() => {
  getCurrentTime();
})

onUnmounted(() => {
  if (timer) {
    clearInterval(timer);
  }
})

</script>

<style lang="scss" scoped>
.header-box {
  width: 100%;
  height: 80px;
  top: -4px;
  position: absolute;
  display: flex;
  background: url('../../assets/image/header-bg.png') no-repeat 0 0;
  background-size: 100% 100%;
  justify-content: space-between;
}

.header-title {
  position: absolute;
  left: 50%;
  transform: translate(-50%);
  font-family: YouShe, serif;
  font-weight: 400;
  font-size: 30px;
  line-height: 70px;
  letter-spacing: .1rem;
  color: #eff6ff;
  background: linear-gradient(1deg, #d4e7ef, #f9feff);
  -webkit-background-clip: text;
}
.header-time{
  position: absolute;
  left: 30px;
  top: 10px;
}
</style>